package com.feri.rbacsys.controller;

import com.feri.rbacsys.entity.ImportOrder;
import com.feri.rbacsys.model.param.ImportParam;
import com.feri.rbacsys.service.intf.DepositoryService;
import com.feri.rbacsys.service.intf.ImportOrderService;
import com.feri.rbacsys.vo.R;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * ┌─┐       ┌─┐ + +
 * ┌──┘ ┴───────┘ ┴──┐++
 * │                 │
 * │       ───       │++ + + +
 * ███████───███████ │+
 * │                 │+
 * │       ─┴─       │
 * │                 │
 * └───┐         ┌───┘
 * │         │
 * │         │   + +
 * │         │
 * │         └──────────────┐
 * │                        │
 * │                        ├─┐
 * │                        ┌─┘
 * │                        │
 * └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 * │ ─┤ ─┤       │ ─┤ ─┤
 * └──┴──┘       └──┴──┘  + + + +
 * 神兽保佑
 * 代码无BUG!
 */
@RestController
@RequestMapping("/api/importorder/")
@Api(tags = "入库订单相关接口")
public class ImportOrderController {


    @Resource
    private ImportOrderService service;

    @PreAuthorize("hasAuthority('imorder:page')")
    @GetMapping("page")
    public R page(int page, int size, String orderNum,String productName){
        return service.selectPage(page, size,orderNum,productName);
    }

    @PreAuthorize("hasAuthority('imorder:import')")
    @PostMapping("import")
    public R importProduct(@RequestBody ImportParam importParam){
        ImportOrder importOrder = new ImportOrder();
        BeanUtils.copyProperties(importParam,importOrder);
        return service.importProduct(importOrder, importParam.getDeadLine());
    }

}
